package com.wangp.procurement.controller;

import com.sun.media.jfxmedia.logging.Logger;
import com.wangp.procurement.dto.ProcurementManagementDto;
import com.wangp.procurement.model.Result;
import com.wangp.procurement.service.ProcurementManagerService;
import com.wangp.procurement.vo.InsertManagementDTO;
import com.wangp.procurement.vo.ProcurementManagementVO;
import com.wangp.procurement.vo.UpsertProcurementManagementDTO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 采购管理 控制层.
 *
 * @author WangPing2
 * <p>createDate 2024-11-17</p>
 **/

@RestController
@RequestMapping("/procurement")
public class ProcurementManagerController {

    @Autowired
    private ProcurementManagerService procurementManagerService;


    /**
     * 采购管理--新增
     * @param  insertManagementDTO
     */
    @PostMapping("/manage")
    public Result<InsertManagementDTO> inster(@RequestBody InsertManagementDTO insertManagementDTO) {
        procurementManagerService.saveManageWithGoods(insertManagementDTO);
        return Result.ok();
    }

   //todo 方法1 分开写 查询（管理）----》对货物是：先删后增
    /**
     * 采购管理---根据id 查询管理对应的货物
     * @param  id
     */
    @GetMapping("/manage/{id}")
    public Result<UpsertProcurementManagementDTO> getById(@PathVariable Integer id) {
        UpsertProcurementManagementDTO managementDTO= procurementManagerService.getByIdWithGoods(id);
        return Result.ok(managementDTO);
    }
    /**
     * 采购管理---根据id修改管理信息和对应的货物信息
     * @param  upsertProcurementManagementDTO
     */
    @PutMapping("/manage/{id}")
    public Result update(@RequestBody UpsertProcurementManagementDTO upsertProcurementManagementDTO) {
        procurementManagerService.updateWhitGoods(upsertProcurementManagementDTO);
        return Result.ok();
    }
    //todo 方法2 比较
    @PostMapping("/manage/{id}")
    public Result<UpsertProcurementManagementDTO> updateNew(@RequestBody UpsertProcurementManagementDTO upsertProcurementManagementDTO) {
        procurementManagerService.updateWhitGoodsNew(upsertProcurementManagementDTO);
        return Result.ok();
    }
    // todo 查询（列表）
    @GetMapping("/manage")
    public ProcurementManagementDto list(ProcurementManagementDto procurementManagementDto) {
        return procurementManagerService.queryPage(procurementManagementDto);
    }

    // todo 采购管理--查询详情
    @GetMapping("/manage/detail/{id}")
    public ProcurementManagementVO query(@PathVariable Integer id) {
        return procurementManagerService.queryInfoById(id);
    }

    // todo 采购管理--失效
    @PatchMapping ("/manage")
    public Integer disable(Integer id) {
        return procurementManagerService.disableInfo(id);
    }
    // 新增/修改
//    @PostMapping("/manage")
//    public Integer upsert(@RequestBody ProcurementManagementVO procurementManagementVO) {
//        return procurementManagerService.saveOrUpdateGoodsManage(procurementManagementVO);
//    }
//
//    // 查询（列表）
//    @GetMapping("/manage")
//    public ProcurementManagementVO list(ProcurementManagementVO Vo) {
//        return procurementManagerService.queryInfoById(1);
//    }
//
//
//    // 查询（详情）
//    @GetMapping("/manage/{id}")
//    public ProcurementManagementVO query(@PathVariable Integer id) {
//        return procurementManagerService.queryInfoById(id);
//    }
//
//    // 删除
//    @DeleteMapping("/manage")
//    public Integer del(Integer id) {
//        return procurementManagerService.deleteInfo(id);
//    }

    // 失效
//    @PatchMapping("/manage")
//    public Integer disable(Integer id) {
//        return procurementManagerService.deleteInfo(id);
//    }
}
